import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FilenameFilter;

import javax.swing.*;
import javax.swing.border.Border;


public class MusicSelector extends JPanel {

    private String[] files;
    public JList jlist;
    //public String selectedFile;
    
    public String selectedFile(){
    	return files[selectedFileIndex()];
    }
    private int selectedFileIndex(){
    	return jlist.getSelectedIndex();
    }
    
	public MusicSelector(){
		
		setLayout(new BorderLayout());
	    JTextArea textArea = new JTextArea(28,54);
	    textArea.setBackground(Color.gray);
	    textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
	    textArea.setEditable(false);
	    File filesName = new File(MusicSelector.class.getProtectionDomain().getCodeSource().getLocation().getPath());
	    String fileName = filesName.getParent() + "\\songs";

	    File dir = new File(fileName);
	    System.out.println(fileName);
	    
	    // Get the (filtered) directory entries
	    List list = new List(12, false); // Set up the list
	    // Sort the list of filenames.
	    FilenameFilter filter;  // Leave for later - we might need to filter out file types
	    files = dir.list();
	    java.util.Arrays.sort(files);

	    // Remove any old entries in the list, and add the new ones
	    list.removeAll();
	    list.add("[Up to Parent Directory]");
	    
	    for (int i = 0; i < files.length; i++){
	      list.add(files[i]);
	      textArea.append(files[i]);
	      textArea.append("\n");
	    }
	    
	    jlist = new JList(files); //data has type Object[]
	    jlist.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
	    jlist.setLayoutOrientation(JList.VERTICAL_WRAP);
	    jlist.setVisibleRowCount(-1);
	    jlist.setSelectedIndex(0);
	    JScrollPane scrollPane = new JScrollPane(jlist);
	    add(scrollPane);
	    setSize(1024,697);
	    setLocation(5, 76);
      setVisible(false);
		
	}
	

}